<script setup>
import {
  Wallet,
  Handbag,
  User,
} from "@element-plus/icons-vue";
import { useRouter } from "vue-router";
const router = useRouter();

const pushToPath = (path) => {
  router.push(path);
};
const logout = () => {
  localStorage.removeItem("admin_token");
  router.push("/admin/login");
};
</script>

<template>
  <div class="admin">
    <el-row  class="admin-head">
      <el-col :span="12" class="logo">范商城管理平台</el-col>
      <el-col :span="1" :offset="11" class="user">
        <el-dropdown>
          <span class="el-dropdown-link">
            <el-avatar :size="40" src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png" />
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item @click="logout">退出</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </el-col>
    </el-row>
    <el-container>
      <el-aside width="200px" class="aside">
        <el-menu class="menu"
        color="#fff"
          active-text-color="#ffd04b">
          <el-sub-menu index="1" >
            <template #title>
              <el-icon><User /></el-icon>
              <span>用户管理</span>
            </template>
            <el-menu-item index="1-1" @click="pushToPath('/admin/user')">用户列表</el-menu-item>
          </el-sub-menu>
          <el-sub-menu index="2">
            
            <template #title>
              <el-icon><Handbag /></el-icon>
            <span>商品管理</span>
            </template>
            <el-menu-item index="2-1" @click="pushToPath('/admin/product')">商品列表</el-menu-item>
          </el-sub-menu>
          <el-sub-menu index="3">
            
            <template #title>
              <el-icon><Wallet /></el-icon>
            <span>充值管理</span>
            </template>
            <el-menu-item index="3-1" @click="pushToPath('/admin/recharge')">充值列表</el-menu-item>
          </el-sub-menu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </div>
</template>

<style scoped lang="scss">
.admin {
  height: 100vh;
  width: 100vw;
  .admin-head {
    background-color: #001529;
    color: #333;
    line-height: 10vh;
    height: 10vh;
    .logo {
      font-size: 24px;
      color: #fff;
      padding-left: 2rem;
    }
    .user {
      cursor: pointer;
      padding-right: 2rem;
      padding-top: 2rem;
    }
  }
  .aside {
    text-align: center;
    height: 90vh;
  }
  .el-main {
    background-color: #e9eef3;
    text-align: center;
  }
}
</style>
